Skip to content

fix(@angular/cli): revert package.json changes if installation tasks fail during update#33563

Merged
clydin merged 2 commits into
angular:mainfrom
clydin:fix-update-rollback-package-json
Jul 20, 2026
Merged

fix(@angular/cli): revert package.json changes if installation tasks fail during update#33563
clydin merged 2 commits into
angular:mainfrom
clydin:fix-update-rollback-package-json

Conversation

@clydin

@clydin clydin commented Jul 14, 2026

Copy link
Copy Markdown
Member

When running the update command, if package manager installation fails (e.g., due to peer dependency conflicts or network issues), the project's package.json is left in an updated state but node_modules is missing or inconsistent.

To prevent leaving the workspace in a broken state, backup the original package.json before applying the update plan, and restore it from the backup if the installation tasks throw an error.

Closes #22162

@clydin
clydin force-pushed the fix-update-rollback-package-json branch from d16c590 to c1c68a5 Compare July 14, 2026 14:33
…fail during update

When running the update command, if package manager installation fails (e.g., due to peer dependency conflicts or network issues), the project's package.json is left in an updated state but node_modules is missing or inconsistent.

To prevent leaving the workspace in a broken state, backup the original package.json before applying the update plan, and restore it from the backup if the installation tasks throw an error.
@clydin
clydin force-pushed the fix-update-rollback-package-json branch from c1c68a5 to a560aa9 Compare July 14, 2026 14:36
…e managers

Other package managers (pnpm, yarn, bun) deterministically reconcile node_modules with the lockfile during installation, making full directory deletion unnecessary and slow.

Keep node_modules cleanup only for npm for now.
@clydin
clydin marked this pull request as ready for review July 14, 2026 14:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a backup and restore mechanism for the package.json file during the update process, ensuring it is restored to its original state if the update fails. Additionally, it optimizes the update process by skipping the node_modules cleaning task when the package manager is not npm. There are no review comments, and the changes are well-implemented, so I have no feedback to provide.

@clydin clydin added target: patch This PR is targeted for the next patch release target: minor This PR is targeted for the next minor release action: review The PR is still awaiting reviews from at least one requested reviewer and removed target: patch This PR is targeted for the next patch release labels Jul 14, 2026
@clydin
clydin requested a review from alan-agius4 July 20, 2026 13:20
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 20, 2026
@clydin
clydin merged commit 8f447ef into angular:main Jul 20, 2026
71 of 72 checks passed
@clydin

clydin commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

This PR was merged into the repository. The changes were merged into the following branches:

@clydin
clydin deleted the fix-update-rollback-package-json branch July 20, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng update deletes node_modules before ensuring it will succeed

2 participants